<template lang="html">
  <div class="">
      <join-people @create="create"/>
    <ul >
      <li v-for="(people, index) in $store.state.people.allpeople" :key="index" >
        <nuxt-link :to="{ name: 'info', params: { info: people.id }}">
          {{ people.name }}
        </nuxt-link>
      </li>
    </ul>
  </div>
</template>

<script>

import axios from '~/plugins/axios'
import domain from '~/plugins/domain'
import JoinPeople from '~/components/JoinPeople.vue';

export default {
  components:{
    JoinPeople
  },
  async fetch ({ store, params }) {
    let allpeople = (await axios.get('/people')).data;
    console.log(allpeople);
    store.commit('people/init', allpeople);
  },
  methods:{
    async create(name){
      const {id} = await domain.create("People", {name});//错误
        // const {data} = await axios.post("/domain/People/create",{name});
      this.$store.commit('people/create', {id:id,name});
    }
  }
}
</script>

<style lang="css">
</style>
